package coder.nav.model.vo;

import coder.nav.enums.NavCashChannelEnums;
import coder.nav.enums.NavCashFlagEnums;
import coder.nav.enums.NavCashTypeEnums;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

@Data
public class NavCashVO implements Serializable {

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("标题")
    private String title;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("消费标识: 0支出 1收入")
    private Integer flag;

    @ApiModelProperty("消费金额: 绝对值")
    private BigDecimal money;

    @ApiModelProperty("支付渠道: 0银联 1微信 2支付宝")
    private Integer channel;

    @ApiModelProperty("消费类型: 0其他 1饮食 2购物 3通讯 4通勤 5游玩 6房租 7薪资")
    private Integer type;

    @ApiModelProperty("用户id")
    private Long userId;

    @ApiModelProperty("年")
    @NotNull
    private Integer year;

    @ApiModelProperty("月")
    @NotNull
    private Integer month;

    @ApiModelProperty("日")
    @NotNull
    private Integer day;

    @ApiModelProperty("创建日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createDate;

    public String getFlagDesc() {
        NavCashFlagEnums e = NavCashFlagEnums.getByKey(this.getFlag());
        if(Objects.isNull(e)) {
            return "";
        }
        return e.getIcon() + " " + e.getValue();
    }

    public String getTypeDesc() {
        NavCashTypeEnums e = NavCashTypeEnums.getByKey(this.getType());
        if(Objects.isNull(e)) {
            return "";
        }
        return e.getIcon() + " " + e.getValue();
    }

    public String getTypeIcon() {
        NavCashTypeEnums e = NavCashTypeEnums.getByKey(this.getType());
        if(Objects.isNull(e)) {
            return "";
        }
        return e.getIcon();
    }

    public String getChannelDesc() {
        NavCashChannelEnums e = NavCashChannelEnums.getByKey(this.getChannel());
        if(Objects.isNull(e)) {
            return "";
        }
        return e.getIcon() + " " + e.getValue();
    }

}
